<?php
/**
 * 积分商城
 */
namespace Admin\Controller;
use Admin\BaseController;
use Common\Model\CouponModel;
use Common\Model\PointMallModel;
use Common\Model\UtilsModel;
use Think\Page;
class PointMallController extends BaseController
{
	/**
	 * 已上线列表
	 * 当前时间戳小于兑换结束的时间戳
	 * Author: hls
	 */
	public function online(){
		$this->baseSearch('online');
	}

	/**
	 * 待上线列表
	 * Author：hls
	 */
	public function prepare()
	{
		$this->baseSearch('prepare');
	}

	/**
	 * 兑换列表
	 * Author:hls
	 */
	public function exchange()
	{
		$this->redirect('exchangeSearch');
	}

	/**
	 * 兑换结束列表
	 * Author:hls
	 */
	public function exchangeEnd()
	{
		$this->baseSearch('exchangeEnd');
	}


	/**
	 * 兑换删除列表
	 * Author:hls
	 */
	public function exchangeDelete()
	{
		$id = I('get.id', null, 'intval');
		$pointMall = M('PointMall', null, DB_MAIN_CFG);
		$result = $pointMall->delete($id);
		if ($result) {
			$this->success('删除成功');
		} else {
			$this->error('删除失败');
		}
	}
	/**
	 * 搜索 action
	 * Author:hls
	 */
	private function baseSearch($action)
	{
		$keywords = I('get.keywords', null, 'htmlspecialchars');
		$deliveryType = I('get.deliveryType', null);

		$pointMall = M('PointMall', null, DB_MAIN_CFG);
		$order='showOrder desc';
		$nowTime = time();
		switch ($action) {
			case 'prepare' :
				$where = 'status = ' . PointMallModel::POINTMALL_IS_PREPARE;
				$display = 'PointMall/prepare.html';
				$assign = 'prepare_list';
				break;
			case 'online'  :
				$where = 'status = ' . PointMallModel::POINTMALL_IS_ONLINE. ' and ' . $nowTime . '< endExchangeTimestamp ';
				$display = 'PointMall/online.html';
				$assign = 'online_list';
				break;
			case 'exchangeEnd'  :
				$where = 'status = ' . PointMallModel::POINTMALL_IS_ONLINE . ' and  endExchangeTimestamp <' . $nowTime ;
				$display = 'PointMall/exchangeEnd.html';
				$assign = 'end_list';
				$order='updateTime desc';
				break;
			default :
				break;
		}
		if (!empty($keywords)) {
			$where .= " and titleInner like '%$keywords%'";
		}
		if (!empty($deliveryType)) {
			$where .= " and  FIND_IN_SET({$deliveryType},deliveryType) ";
		}

		import("ORG.Util.Page");
		$count = $pointMall->where($where)->count();
		$this->smarty->assign('totalDataCount',$count);

		$limit = I('get.limit',10,'int');	//每页显示条数
		$Page = new Page($count, $limit);
		fetchPage($this->smarty, $Page);
		$Page->parameter = "keywords=$keywords";
		$list = $pointMall
			->where($where)
			->order($order)
			->limit($Page->firstRow , $Page->listRows)
			->select();



		$deliveryTypeKv = PointMallModel::getDeliveryType();

		$this->smarty->assign('keywords',$keywords);
		$this->smarty->assign('deliveryTypeKv',$deliveryTypeKv);
		$this->smarty->assign('deliveryType',$deliveryType);
		$this->smarty->assign('limit',$limit);
		$this->smarty->assign($assign, $list);

		$this->smarty->assign('userLevelSwitch',POINTMALL_ASK_USERLEVEL);
		$this->smarty->display($display);
	}

	/**
	 * 用于兑换记录的搜索
	 */
	public function exchangeSearch(){
		
		$keywords = I('get.keywords', null, 'htmlspecialchars');
		$startDate = I('get.startDate',date('Y-m-d',strtotime("-6 months",time())));
		$endDate = I('get.endDate',date('Y-m-d'));
		$id = I('get.id',null);
		$exchangeLog = M('exchangeLog', null, DB_MAIN_CFG);
		$export=I('get.export',0,'int');

		$display = 'PointMall/commonRecord.html';
		
		$where ='1';
		if($id){
			$where .=' and exchange_log.pid=' . $id;
		}
		if(!empty($startDate)){
			$where .= ' and exchange_log.exchangeTime > ' . strtotime($startDate);
		}
		if(!empty($endDate)){
			$where .= ' and exchange_log.exchangeTime < ' . (strtotime($endDate)+UtilsModel::ONE_DAY);
		}
		if(!empty($keywords)){
			$idArr = M('point_mall',null,DB_MAIN_CFG)->where("titleList like '%$keywords%'")->getField('id',true);
			if($idArr){
				$idStr = implode(',',$idArr);
				$where .= " and (realName like '%$keywords%' or nickname like '%$keywords%' or phone like '%$keywords%' or pid IN ($idStr))";
			} else{
				$where .= " and (realName like '%$keywords%' or nickname like '%$keywords%' or phone like '%$keywords%')";
			}

		}

		$exchangeLogStatusEnum=PointMallModel::getExchangeStatus();
		$deliveryTypeKv=PointMallModel::getDeliveryType();

		if($export){
			$list = $exchangeLog
				->field('exchange_log.uid,exchange_log.cardNum,exchange_log.realName,exchange_log.nickname,exchange_log.phone,exchange_log.address,point_mall.titleList,exchange_log.exchangeTime,exchange_log.status,exchange_log.selectedWay')
				->join('point_mall on point_mall.id = exchange_log.pid')
				->where($where)
				->select();
			$data = array();
			foreach ($list as $key => $val){
				$data[$key]=array();
				$data[$key]['title'] = $val['titleList'];
				$data[$key]['uid'] = $val['uid'];
				$data[$key]['nickname'] = $val['nickname'];
				$data[$key]['realName'] = $val['realName'];
				$data[$key]['phone'] = "\t".$val['phone'];
				$data[$key]['address'] = $val['address'];
				$data[$key]['cardNum'] = "\t".$val['cardNum'];
				$data[$key]['addTime'] = "\t".date('Y-m-d H:i:s',$val['exchangeTime']);
				$data[$key]['status'] = $exchangeLogStatusEnum[$val['status']];
				$data[$key]['deliveryType'] = $deliveryTypeKv[$val['selectedWay']];
			}
			exportCSV($data, array('活动名','用户ID','昵称','真实姓名','手机号码','配送地址','卡号','报名时间','状态','消费方式'),'兑换清单_'.date('Ymd',time()));
			exit;

		}
		else{
			$count = $exchangeLog
				->join('point_mall on point_mall.id = exchange_log.pid')
				->where($where)
				->count();
			$this->smarty->assign('totalDataCount',$count);

			$limit = I('get.limit',10,'int');	//每页显示条数
			$Page = new Page($count, $limit);
			fetchPage($this->smarty, $Page);
			$Page->parameter = "keywords=$keywords";
			$list = $exchangeLog
				->field('exchange_log.cardNum,exchange_log.realName,exchange_log.nickname,exchange_log.phone,exchange_log.address,exchange_log.status,point_mall.titleList,exchange_log.exchangeTime,exchange_log.selectedWay')
				->join('point_mall on point_mall.id = exchange_log.pid')
				->where($where)
				->limit($Page->firstRow , $Page->listRows)
				->order('exchange_log.id desc')
				->select();

			$this->smarty->assign('deliveryTypeKv',$deliveryTypeKv);
			$this->smarty->assign('limit',$limit);
			$this->smarty->assign('id', $id);
			$this->smarty->assign('keywords', $keywords);
			$this->smarty->assign('startDate', $startDate);
			$this->smarty->assign('endDate', $endDate);
			$this->smarty->assign('list', $list);
			

			$pointMall=PointMallModel::getList(PointMallModel::POINTMALL_IS_ONLINE,0,9999999,0,0,CLIENT_FROM_ALL,-1);
			$this->smarty->assign('pointMallList', $pointMall['data']);
			$this->smarty->assign('statusEnum', $exchangeLogStatusEnum);
			$this->smarty->display($display);
		}



	}


	/**
	 * 新增兑换
	 */
	public function exchangeAdd()
	{
		//兑换类型列表
		//物品类型列表
		$contentTypes = getContentTypeKv();
		//分类
		$deliveryType = PointMallModel::getDeliveryType();
		if (IS_POST) {
			//验证规则
			$rules = array(
				array('titleInner', 'require', '内标题必须填写'),
				array('userLevelRequire', 'require', '会员必须填写'),
				array('points', 'require', '积分必须填写'),
				array('stock','require','库存必须填写'),
				array('quota', 'require', '限购数量必须填写'),
				array('beginShowTimestamp', 'require', '显示开始时间必须填写'),
				array('beginExchangeTimestamp', 'require', '兑换开始时间必须填写'),
				array('endExchangeTimestamp', 'require', '兑换结束时间必须填写'),
				array('listPic', 'require', '缩略图必须要上传图片'),
				array('cover', 'require', '封面图必须要上传图片'),
			);
			//自动完成 将时间自动转换为时间戳
			$auto = array(
				array('beginShowTimestamp', 'strtotime', 3, 'function'),
				array('beginExchangeTimestamp', 'strtotime', 3, 'function'),
				array('endExchangeTimestamp', 'strtotime', 3, 'function'),
				array('content', 'html_entity_decode', 3, 'function'),
				array('updateTime', 'time', 3, 'function'),
			);

			$pointMall = M('PointMall', null, DB_MAIN_CFG);
			$codeList  = M('card_code',null,DB_MAIN_CFG);
			$card_info = M('card_base_info',null,DB_MAIN_CFG);
			if ($data = $pointMall->validate($rules)->auto($auto)->create()) {
				$deliveryTypeArr=I('post.deliveryType');
				$data['deliveryType']=implode(',',$deliveryTypeArr);

				$goodsTypeArr=I('post.goodsType');//商品分类
				$data['goodsType']=implode(',',$goodsTypeArr);
				if(count($goodsTypeArr)<=0){
					$this->error('商品分类至少从属一个');
				}


				$content		= I('post.content');//内容
				$content		= htmlspecialchars_decode($content);
				$nativeRT		= UtilsModel::NativeThumb($content);
				$data['relativePhoto']	= $nativeRT[0];
				$data['content']		= $nativeRT[1];
				
				if(POINTMALL_CLIENT_SHOW){
					$clientShow=I('post.clientShow',null);
					if(count($clientShow)<=0){
						$this->error('文章必须指定至少一个展现渠道');
					}
					$data['clientShow']=implode(',',$clientShow);
				}
				else{
					$data['clientShow'] = CLIENT_SHOW_WAP;
				}
				

				//如果标题列表不填写时使用内标题
				if ($data['titleList'] == null) {
					$data['titleList'] = $data['titleInner'];
				}
				//显示开始时间不能小于兑换开始时间
				if ($data['beginShowTimestamp'] < 'beginExchangeTimestamp') {
					$this->error('开始时间不能小于兑换开始时间');
				}

				//如果选择是卡券 库存大于卡券库的数量
				if(in_array(PointMallModel::DELIVERY_CARD,$deliveryTypeArr)){
					if( $data['cardId'] + 0 < 1 ){
						$this->error('请指定卡券');
					}
					//获取根据输入的库存获取相对应的数据
					$code_list_count = $codeList
						->where('status = '.CouponModel::CODE_STATUS_DEFAULT.' and objType=0 and objID =0 and cardId=' . $data['cardId'])
						->count();
					if($data['stock']>$code_list_count){
						$this->error('卡券库存不足');
					}
				}
				if(in_array(PointMallModel::DELIVERY_SEND,$deliveryTypeArr)){
					if(!$data['deliverArea']){
						$this->error('请输入配送区域。提示：快递费用不填写，则不收取快递费用');
					}
				}
				if(in_array(PointMallModel::DELIVERY_PHONE,$deliveryTypeArr)){
					if(!$data['pickAddress']){
						$this->error('请输入自取地址');
					}
				}
				$result = $pointMall->add($data);
				if ($result) {
					//如果选择卡券类型
					if(in_array(PointMallModel::DELIVERY_CARD,$deliveryTypeArr)){

						$card_list_data = array(
							'objType'=>OBJ_TYPE_POINTMALL,
							'objID' => $result,
						);

						//判断选择有效期类型
//						if($_POST['cardType'] == CARD_COUSTOM_DAY){
//							$card_list_data = array(
//								'beginTimestamp' => strtotime($_POST['beginCardTimestamp']),
//								'endTimestamp' => strtotime($_POST['endCardTimestamp']),
//								'objType'=>OBJ_TYPE_POINTMALL,
//								'objID' => $result,
//							);
//						}else{
//							$card_list_data = array(
//								'fixedBeginTerm' => $_POST['fixedBeginTerm'],
//								'fixedTerm' => $_POST['fixedTerm'],
//								'objType'=>OBJ_TYPE_POINTMALL,
//								'objID' => $result,
//							);
//						}
						//获取根据输入的库存获取相对应的数据
						$codeList
							->where('status = 0 and objType=0 and objID =0  and cardId=' . $data['cardId'])
							->order('createTimestamp desc')
							->limit($data['stock'])
							->save($card_list_data);

						//在卡券信息基础表中更新投放数量和上线次数
						//更新上线次数
						$card_info->where('id='.$data['cardId'])->setInc('onlineNum');
						//更新投放数量
						$card_info->where('id='.$data['cardId'])->setInc('launchNum',$data['stock']);
					}
					$this->success('添加成功');
				} else {
					$this->error('添加失败');
				}
			} else {
				$this->error($pointMall->getError());
			}
		}
		else {
			//卡券信息列表
			$card_info  = M('card_base_info',null,DB_MAIN_CFG);
			$card_info_list = $card_info->where('status='.ENABLE_ENABLE)->select();

			
			if(POINTMALL_CLIENT_SHOW){
				$clientShow=array_slice(C('CLIENT_SHOW'),1,null,true);
				$this->smarty->assign('clientShow',$clientShow);
			}
			$this->smarty->assign('clientShowSwitch',POINTMALL_CLIENT_SHOW);
			$this->smarty->assign('userLevelSwitch',POINTMALL_ASK_USERLEVEL);

			$goodsTypeArr=PointMallModel::getGoodsType();
			$this->smarty->assign('goodsType',$goodsTypeArr);

			//需发货-自提地址
			$selfAddress = M('cfg_config',null,DB_MAIN_CFG)->where("cfgName='SELF_PICK_ADDRESS'")->getField("cfgValue");
			if($selfAddress){
				$selfAddressArr = explode(',',$selfAddress);
				$this->smarty->assign('addArr',$selfAddressArr);
			}

			//快递费用开关
			$paySwitch = EXPRESS_DELIVERY_PAY;
			$this->smarty->assign('paySwitch',$paySwitch);

			$this->smarty->assign('card_info_list',$card_info_list);
			$this->smarty->assign('picWidth', C("POINT_THUMB_WIDTH"));
			$this->smarty->assign('picHeight', C("POINT_THUMB_HEIGHT"));
			$this->smarty->assign('listPicWidth',  C("POINTMALL_LIST_PIC_WIDTH"));
			$this->smarty->assign('listPicHeight', C("POINTMALL_LIST_PIC_HEIGHT"));

			$this->smarty->assign('contentType',$contentTypes);
			$this->smarty->assign('typeList', $deliveryType);
			$this->smarty->display('PointMall/exchangeEdit.html');
		}
	}




	/**
 	* 兑换编辑列表
 	* Author:hls
 	*/
	public function exchangeEdit()
	{
		$id = I('get.id', null, 'intval');
		//物品类型列表
		$contentTypes = getContentTypeKv();
		//分类
		$deliveryType = PointMallModel::getDeliveryType();

		$pointMall = M('PointMall', null, DB_MAIN_CFG);
		$codeList = M('card_code',null,DB_MAIN_CFG);
		if (IS_POST) {
			//验证规则
			$rules = array(
				array('titleInner', 'require', '内标题必须填写'),
				array('userLevelRequire', 'require', '会员必须填写'),
				array('points', 'require', '积分必须填写'),
				array('stock', 'require', '库存必须填写'),
				array('quota', 'require', '限购数量必须填写'),
				array('beginShowTimestamp', 'require', '显示开始时间必须填写'),
				array('beginExchangeTimestamp', 'require', '兑换开始时间必须填写'),
				array('endExchangeTimestamp', 'require', '兑换结束时间必须填写'),
				array('listPic', 'require', '列表图必须要上传图片'),
				array('cover', 'require', '封面图必须要上传图片'),
			);
			//自动完成 将时间自动转换为时间戳
			$auto = array(
				array('beginShowTimestamp', 'strtotime', 3, 'function'),
				array('beginExchangeTimestamp', 'strtotime', 3, 'function'),
				array('endExchangeTimestamp', 'strtotime', 3, 'function'),
				array('content', 'html_entity_decode', 3, 'function'),
				array('updateTime', 'time', 3, 'function'),
			);

			if ($data = $pointMall->validate($rules)->auto($auto)->create()) {

				$deliveryTypeArr=I('post.deliveryType');
				$data['deliveryType']=implode(',',$deliveryTypeArr);


				$goodsTypeArr=I('post.goodsType');//商品分类
				$data['goodsType']=implode(',',$goodsTypeArr);
				if(count($goodsTypeArr)<=0){
					$this->error('商品分类至少从属一个');
				}
				
				$content		= I('post.content');//内容
				$content		= htmlspecialchars_decode($content);
				$nativeRT		= UtilsModel::NativeThumb($content);
				$data['relativePhoto']	= $nativeRT[0];
				$data['content']		= $nativeRT[1];
				$data['pickAddress'] = htmlspecialchars_decode(I('post.pickAddress'));
				$data['isShowStock'] = I('post.isShowStock',0,'intval');

				if(POINTMALL_CLIENT_SHOW){
					$clientShow=I('post.clientShow',null);
					if(count($clientShow)<=0){
						$this->error('文章必须指定至少一个展现渠道');
					}
					$data['clientShow']=implode(',',$clientShow);
				}
				else{
					$data['clientShow'] = CLIENT_SHOW_WAP;
				}

				$stock = $pointMall->where('id=' . $data['id'])->getField('stock');
				//如果标题列表不填写时使用内标题
				if ($data['titleList'] == null) {
					$data['titleList'] = $data['titleInner'];
				}
				//显示开始时间不能小于兑换开始时间
				if ($data['beginShowTimestamp'] < 'beginExchangeTimestamp') {
					$this->error('开始时间不能小于兑换开始时间');
				}

				//如果选择是卡券 库存大于卡券库的数量
				if(in_array(PointMallModel::DELIVERY_CARD,$deliveryTypeArr)){
					if($data['cardId']+0<1){
						$this->error('请指定卡券');
					}

					//判断库存是否小于原先库存
					if($data['stock']<$stock){
						$this->error('不能小于原先库存');
					}

					//获取根据输入的库存获取相对应的数据
					$code_list_count = $codeList->where('status = 0 and objType=0 and objID =0 and cardId=' . $data['cardId'])	->count();

					//判断库存是否小于总库存
					$addVal=$data['stock']-$stock;
					if($addVal>$code_list_count){
						$this->error('卡券库存不足');
					}


					//判断选择有效期类型
					$card_list_data = array(
						'objType'	=>OBJ_TYPE_POINTMALL,
						'objID' =>  $data['cardId'],
					);

					if ($addVal>0) {
						$codeList
							->where('status = 0  and objType=0 and objID =0 and cardId=' . $data['cardId'])
							->order('createTimestamp desc')
							->limit($addVal)
							->save($card_list_data);
					}
				}
				if(in_array(PointMallModel::DELIVERY_SEND,$deliveryTypeArr)){
					if(!$data['deliverArea']){
						$this->error('请输入配送区域。提示：快递费用不填写，则不收取快递费用');
					}
				}
				if(in_array(PointMallModel::DELIVERY_PHONE,$deliveryTypeArr)){
					if(!$data['pickAddress']){
						$this->error('请输入自取地址');
					}
				}


				//保存积分兑换的信息
				$result = $pointMall->save($data);
				if (false !== $result) {
					//刷新缓存
					$refreshData=$pointMall->where('id=' . $data['id'])->find();
					S('pointMall_'. $data['id'],$refreshData);

					//如果选择卡券类型
					$this->success('更改成功');
				} else {
					$this->error('更改失败');
				}
			} else {
				$this->error($pointMall->getError());
			}
		}
		else {
			//卡券信息列表
			$card_info  = M('card_base_info',null,DB_MAIN_CFG);
			$card_code = M('card_code',null,DB_MAIN_CFG);
			$card_info_list = $card_info->where('status='.ENABLE_ENABLE)->select();
			$card_item = $card_code->where('objType='.OBJ_TYPE_POINTMALL.' and objID=' . $id)->find();
			$card_item['beginTimestamp'] = empty($card_item['beginTimestamp'])?null: date('Y-m-d h:m:s',$card_item['beginTimestamp']);
			$card_item['endTimestamp'] = empty($card_item['endTimestamp'])?null: date('Y-m-d h:m:s',$card_item['endTimestamp']);
			$reulst = $pointMall->find($id);

			$clientShow=array_slice(C('CLIENT_SHOW'),1,null,true);
			$this->smarty->assign('clientShow',$clientShow);

			$goodsTypeArr=PointMallModel::getGoodsType();
			$this->smarty->assign('goodsType',$goodsTypeArr);
			$this->smarty->assign('selectedGoodsType',explode(',',$reulst['goodsType']));

			

			$selectedClient=explode(',',$reulst['clientShow']);
			$this->smarty->assign('selectedClients',$selectedClient);
			$this->smarty->assign('clientShowSwitch',POINTMALL_CLIENT_SHOW);
			$this->smarty->assign('userLevelSwitch',POINTMALL_ASK_USERLEVEL);
			//需发货-自提地址
			$selfAddress = M('cfg_config',null,DB_MAIN_CFG)->where("cfgName='SELF_PICK_ADDRESS'")->getField("cfgValue");
			if($selfAddress){
				$selfAddressArr = explode(',',$selfAddress);
				$this->smarty->assign('addArr',$selfAddressArr);
			}

			//快递费用开关
			$paySwitch = EXPRESS_DELIVERY_PAY;
			$this->smarty->assign('paySwitch',$paySwitch);


			$this->smarty->assign('card_info_list',$card_info_list);
			$this->smarty->assign('card_item',$card_item);
			$this->smarty->assign('obj', $reulst);
			$this->smarty->assign('picWidth', C("POINT_THUMB_WIDTH"));
			$this->smarty->assign('picHeight', C("POINT_THUMB_HEIGHT"));
			$this->smarty->assign('listPicWidth',  C("POINTMALL_LIST_PIC_WIDTH"));
			$this->smarty->assign('listPicHeight', C("POINTMALL_LIST_PIC_HEIGHT"));
			$this->smarty->assign('contentType',$contentTypes);
			$this->smarty->assign('typeList', $deliveryType);
			$this->smarty->display('PointMall/exchangeEdit.html');
		}
	}


	/**
	 * 流量兑换统计
	 * Author：hls
	 */
	public function traffic()
	{
		$traffic_record = M('TrafficRecord', null, DB_MAIN_CFG);
		$count = $traffic_record->count();
		$Page = new Page($count, 10);
		fetchPage($this->smarty, $Page);
		$record_list = $traffic_record
			->limit($Page->firstRow , $Page->listRows)
			->select();
		$deliveryType = PointMallModel::getDeliveryType();
		$this->smarty->assign('typelist', $deliveryType);
		$this->smarty->assign('list', $record_list);
		$this->smarty->display('PointMall/traffic.html');
	}

	/**
	 * 保存自提地址
	 * Author:wwl
	 */
	public function savePickAddress(){
		$add1 = I('post.add1',null);
		$add2 = I('post.add2',null);
		$address = null;$addArr = array();
		if(!$add1 && !$add2){
//       $this->ajaxReturn(array('status'=>1,'msg'=>'请输入至少一个有效地址后再提交'));

		} else if($add1 && $add2){
			$addArr[0] = $add1;
			$addArr[1] = $add2;
		} else if($add1 && !$add2){
			$addArr[0] = $add1;
		} else{
			$addArr[0] = $add2;
		}
		$address = implode(',',$addArr);
		$this->smarty->assign('addArr',$addArr);
		$html = $this->smarty->fetch('PointMall/pickAddress.html');

		$configM = M('cfg_config',null,DB_MAIN_CFG);
		$data = $configM->where("cfgName='SELF_PICK_ADDRESS'")->find();
		if($data){
			if($data['cfgValue'] == $address){
//          $this->smarty->assign('addArr',$addArr);
//          $html = $this->smarty->fetch('PointMall/pickAddress.html');
				$this->ajaxReturn(array('status'=>0,'msg'=>'地址配置成功','dataHTML'=>$html));
			} else{
				$res=$configM->where("cfgName='SELF_PICK_ADDRESS'")->setField("cfgValue","$address");
				if($res !== false){

					$this->ajaxReturn(array('status'=>0,'msg'=>'地址配置成功','dataHTML'=>$html));
				}else{
					$this->ajaxReturn(array('status'=>1,'msg'=>'地址配置失败'));
				}
			}
		}else{
			$res = $configM->add(array('cfgName'=>'SELF_PICK_ADDRESS','cfgValue'=>$address,'desc'=>'自提地址'));
			if($res){
				$this->ajaxReturn(array('status'=>0,'msg'=>'地址配置成功','dataHTML'=>$html));
			} else{
				$this->ajaxReturn(array('status'=>1,'msg'=>'地址配置失败'));
			}
		}
	}

	public function adjustSales(){
		$id=I('post.id',0,'int');
		$num=I('post.num',0,'int');
		if($num<=0){
			$this->ajaxReturn(array('status'=>1,'msg'=>'数值设置请大于0'));
		}

		$param=PointMallModel::tempStock($id);
		if($num>$param['showStock']){
			$this->ajaxReturn(array('status'=>1,'msg'=>'数值设置请小于等于'.$param['showStock']));
		}
		M('point_mall',null,DB_MAIN_CFG)->where('id='.$id)->setInc('soldAdjust',$num);
		$this->ajaxReturn(array('status'=>0,'msg'=>'操作成功'));


	}
}
